const Koa = require('koa')
const path = require('path')
const fs = require('fs')
const login = require('./login')
const bodyParse = require('./middleware/bodyParse')
// const bodyParse = require('koa-bodyparser') // 解析路径参数及文件上传
const static = require('./middleware/static')
// const static = require('koa-static')   // 静态文件目录返回
const Router = require('./middleware/router')
// const Router = require('koa-router')  // 路由处理

let app = new Koa()
let router = new Router()
app.use(bodyParse(path.resolve(__dirname, 'upload')))
app.use(static(__dirname))
// app.use(async (ctx, next) => {
//     if (ctx.path === '/form' && ctx.method === 'GET') {
//         let r = fs.createReadStream(path.resolve(__dirname, 'form.html'))
//         ctx.set('Content-Type', 'text/html;charset=utf-8')
//         ctx.body = r
//     } else {
//         await next()
//     }
// })

router.get('/login', async (ctx, next) => {
    console.log('login-get')
    await next()
})
router.post('/login', async (ctx, next) => {
    console.log('login-post')
    await next()
})


app.use(router.routes())
app.use((ctx, next) => {
    ctx.body = 'all'
    return next()
})


login(app)


app.listen(3000, function () {
    console.log('server start 3000')
})
